package cn.itcast.account.service;

import io.seata.rm.tcc.api.BusinessActionContext;
import io.seata.rm.tcc.api.BusinessActionContextParameter;
import io.seata.rm.tcc.api.LocalTCC;
import io.seata.rm.tcc.api.TwoPhaseBusinessAction;

/**
 * @author liudo
 * @version 1.0
 * @project seata-demo
 * @description TCC服务
 * @date 2023/8/24 14:11:54
 */
@LocalTCC
public interface AccountTCCService {

    /**
     * 扣除 - 冻结资源
     *
     * @param userId 用户id
     * @param money  钱
     */
    @TwoPhaseBusinessAction(name = "deduct",
            commitMethod = "commit",
            rollbackMethod = "rollback")
    void deduct(@BusinessActionContextParameter(paramName = "userId") String userId,
                @BusinessActionContextParameter(paramName = "money") int money);

    /**
     * 提交调用的方法
     *
     * @param context 上下文
     */
    boolean commit(BusinessActionContext context);

    /**
     * 回滚 调用的方法
     *
     * @param context 上下文
     */
    boolean rollback(BusinessActionContext context);
}
